﻿#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
#endregion Using Statements
/// by Torey J. Scheer
/// Game Class used to test various made methods.
/// 
/// ???
namespace Turn_ament
{
    class MouseControl
    {
        #region Attributes
        private bool singleClick;
        public ImageObject image;
        private MouseState current, previous;
        private Vector2 point;
        private Rectangle rectangle;
        #endregion Attributes

        #region Constructors
        public MouseControl()
        {
            image = null;
            current = Mouse.GetState();
            Update();
        }

        public MouseControl(ImageObject imageObject)
            : this()
        {
            image = imageObject;
        }
        #endregion Constructors

        #region Properties

        #region Get-Set Properties
        public MouseState Current
        {
            get { return current; }

            set { current = value; }
        }

        public MouseState Previous
        {
            get { return previous; }

            set { previous = value; }
        }

        public bool SingleClicked
        {
            get { return singleClick; }

            set { singleClick = value; }
        }
        #endregion Get-Set Properties

        #region Get Properties

        #region Left Button
        public bool LeftDown
        {
            get { return (current.LeftButton == ButtonState.Pressed && previous.LeftButton == ButtonState.Pressed); }
        }

        public bool LeftUp
        {
            get { return (current.LeftButton == ButtonState.Released && previous.LeftButton == ButtonState.Released); }
        }

        public bool LeftClick
        {
            get { return (current.LeftButton == ButtonState.Released && previous.LeftButton == ButtonState.Pressed); }
        }
        #endregion Left Button

        public bool RightDown
        {
            get { return (current.RightButton == ButtonState.Pressed && previous.RightButton == ButtonState.Pressed); }
        }

        public bool RightUp
        {
            get { return (current.RightButton == ButtonState.Released && previous.RightButton == ButtonState.Released); }
        }

        public bool RightClick
        {
            get { return (current.RightButton == ButtonState.Released && previous.RightButton == ButtonState.Pressed); }
        }

        public bool MiddleDown
        {
            get { return (current.MiddleButton == ButtonState.Pressed && previous.MiddleButton == ButtonState.Pressed); }
        }

        public bool MiddleUp
        {
            get { return (current.MiddleButton == ButtonState.Released && previous.MiddleButton == ButtonState.Released); }
        }

        public int ScrollChange
        {
            get { return current.ScrollWheelValue - previous.ScrollWheelValue; }
        }

        public Vector2 Point
        {
            get { return point; }
        }

        public Vector2 PrevPoint
        {
            get { return new Vector2(previous.X, previous.Y); }
        }

        public Rectangle Rectangle
        {
            get { return rectangle; }
        }

        public Rectangle PrevRectangle
        {
            get { return new Rectangle(previous.X, previous.Y, rectangle.Width, rectangle.Height); }
        }
        #endregion Get Properties

        #endregion Properties

        #region Methods
        public void Update()
        {
            singleClick = false;
            previous = current;
            current = Mouse.GetState();
            point.X = rectangle.X = current.X;
            point.Y = rectangle.Y = current.Y;
            if (image != null)
                image.Point = point;
        }

        /// <summary> Checks if your mouse has clicked a specific Rectangle AND if it's a SingleClick(). </summary>
        /// <param name="area">The area being checked.</param>
        /// <returns>If clicked.</returns>
        public bool CheckIfClicked(Rectangle value)
        {
            if (value.Intersects(rectangle))
            {
                return SingleClick();
            }
            return false;
        }

        /// <summary> Processes a singular mouse click. </summary>
        /// <returns>If the current button press is the same as the last.</returns>
        public bool SingleClick()
        {
            if (singleClick == false && current.LeftButton == ButtonState.Released && previous.LeftButton == ButtonState.Pressed)
            {
                singleClick = true;
                return true;
            }
            return false;
        }
        #endregion Methods

        #region Draw
        public void Draw()
        {
            if (image != null)
                image.Draw();
            image.Point = point;
        }
        #endregion Draw
    }
}
